<#assign module="member"/>

<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/form.css">
</@override>
<@override name="body">

	<div class="row">
	
		<form id="submit_form" action="${ctx}/member/updateCompany" method="post">
		<input type="hidden" name="CSRFToken" value="${CSRFToken}"/>
		<input type="hidden" name="id" value="${member.id}">
		<@shiro.hasPermission name='allowsign'>
        	<input type="hidden" name="allowsign" value="true"/>
        </@shiro.hasPermission>
        
		<div class="col-md-4 col-lg-4">
			<div class="panel panel-default">
				<div class="panel-heading">
					填写客户信息
			    </div>
			    <div class="panel-body">
    				
    				<div class="form-group">
	                    <label>客户头像：</label>
	                    <br/>
		                <img width="150" height="150" <#if member.photo??>src="${ctx}/upload/member/${member.photo}"<#else>src="${ctx}/assets/css/images/member_img.png"</#if> />
	                	
	                </div>
		                
    				<div class="form-group">
	                    <label><em>*</em>客户类型：</label>
	                    <select class="form-control" id="type" name="type" required>
	                    	<#if typechange??>
	                    		<option <#if typechange=='0'>selected='selected'</#if> data-type="0" value="个人用户">个人用户</option>
		                    	<option <#if typechange=='1'>selected='selected'</#if> data-type="1" value="企业用户">企业用户</option>
		                    	<option <#if typechange=='2'>selected='selected'</#if> data-type="2" value="VIP用户">VIP用户</option>
	                    	<#else>
	                    		<option <#if member.type?? && member.type=='个人用户'>selected='selected'</#if> data-type="0" value="个人用户">个人用户</option>
		                    	<option <#if member.type?? && member.type=='企业用户'>selected='selected'</#if> data-type="1" value="企业用户">企业用户</option>
		                    	<option <#if member.type?? && member.type=='VIP用户'>selected='selected'</#if> data-type="2" value="VIP用户">VIP用户</option>
	                    	</#if>
	                    </select>
	                </div>
	                
	                <div class="form-group">
	                    <label><em>*</em>所属公司：</label>
	                    <select class="form-control" id="companyId" name="companyId" required>
	                    	<#list companys as company>
                    			<option value="${company.id}" <#if member.company?? && member.company.id==company.id>selected="selected"</#if>>${company.abbreviation?if_exists}</option>
							</#list>
	                    </select>
	                </div>
	                
	                <div class="form-group">
	                    <label><em>*</em>代驾收费：</label>
	                    <select class="form-control" id="areaId" name="areaId">
	                    	<option value="">公司统一收费</option>
	                    	<#list arealist as area>
                    			<option value="${area.id}" <#if member.areaId?? && member.areaId==area.id>selected="selected"</#if>>${area.name?if_exists}</option>
							</#list>
	                    </select>
	                </div>
	                
	                <@zhuan>
		                <div class="form-group">
		                    <label><em>*</em>专车收费：</label>
		                    <select class="form-control" id="areaCarId" name="areaCarId">
		                    	<option value="">公司统一收费</option>
		                    	<#list arealist as area>
	                    			<option value="${area.id}" <#if member.areaCarId?? && member.areaCarId==area.id>selected="selected"</#if>>${area.name?if_exists}</option>
								</#list>
		                    </select>
		                </div>
	                </@zhuan>
	                
	               	<div class="form-group">
	                    <label>联系人：</label>
	                   	<input class="form-control" id="name" name="name" type="text" value="${member.name?if_exists}">
	                </div>
	                
	                <div class="form-group">
	                    <label>客户来源：</label>
	                    <input class="form-control" id="fromSource" name="fromSource" value="${member.fromSource?if_exists}" type="text"/>
	                </div>
	                
	                <div class="form-group">
	                    <label>推荐人：</label>
	                    <input class="form-control" id="introducer" name="introducer" value="${member.introducer?if_exists}" type="text"/>
	                </div>
	                
	                <div class="form-group">
	                    <label>推荐人类型：</label>
	                    <p class="form-control-static">
                    		<label style="padding-right:30px;">
								<input type="radio" name="introduceType" value="0" <#if member.introduceType?? && member.introduceType==0>checked="checked"</#if>> 客户推荐
							</label>
							<label style="padding-right:30px;">
								<input type="radio" name="introduceType" value="1" <#if member.introduceType?? && member.introduceType==1>checked="checked"</#if>> 服务人员推荐
							</label>
						</p>
	                </div>
	                
	                <div class="form-group">
	                    <label>单位名称：</label>
	                    <input class="form-control" id="agencyName" name="agencyName" value="${member.agencyName?if_exists}" type="text"/>
	                </div>
	                
	                <div class="form-group">
	                    <label>单位地址：</label>
	                    <textarea class="form-control" cols="20" id="agencyAddress" name="agencyAddress" rows="2">${member.agencyAddress?if_exists}</textarea>
	                </div>
	                
	                <div class="form-group">
	                    <label>备注：</label>
	                    <textarea class="form-control" cols="20" id="memo" name="memo" rows="2">${member.memo?if_exists}</textarea>
	                </div>
	                
	                <div class="form-group">
	                    <label for="gender">是否允许签单：</label>
                    	<label style="padding-right:20px;">
						  <input <@shiro.lacksPermission name='allowsign'>disabled="disabled"</@shiro.lacksPermission> type="checkbox" name="isOverdraw" <#if member.isOverdraw??>${member.isOverdraw?string('checked="checked"','')}</#if>/>
						</label>
	                </div>
	                
	                <div class="form-group" style="margin-left:10px;">
		                <input type="submit" class="btn btn-primary" value="保存">
		                <input type="button" class="btn btn-default" onclick="window.location.href = '${ctx}/member/list';" value="返回">
		            </div>
        		</div>
			</div>
		</div>
	
		<div class="col-md-8 col-lg-8">
			<div class="panel panel-default" style="min-height: 833px;">
				<div class="panel-heading">
					关联手机   
			    </div>
			    <div class="form-group" style="margin-top:10px;margin-left:10px;">
		        	<input type="button" id="add-phone" class="btn btn-default" value="添加">
		        </div>
				<table id="phone-table" class="table" style="margin-left:10px;">
					<tr>
						<th width="5%">#</th>
						<th width="20%">手机号</th>
						<th width="20%">姓名</th>
						<th width="25%">常用目的地</th>
						<th width="20%">车牌号</th>
						<th width="10%">操作</th>
					</tr>
					<#if member.memberAccounts?? && (member.memberAccounts?size>0)>
						<#list member.memberAccounts as ma>
							<tr>
							   <td>${ma_index+1}</td>
							   <td><input class="form-control phone-input" type="text" name="memberAccounts[${ma_index}].phone" value="${ma.phone?if_exists}" /></td>
							   <td><input class="form-control" type="text" name="memberAccounts[${ma_index}].name" value="${ma.name?if_exists}" /></td>
							   <td><input class="form-control" type="text" name="memberAccounts[${ma_index}].address" value="${ma.address?if_exists}" /></td>
							   <td><input class="form-control" type="text" name="memberAccounts[${ma_index}].carNumber" value="${ma.carNumber?if_exists}" /></td>
							   <td><a href='javascript:;' class='btn btn-default deletethis'>删除</a><input type="hidden" name="memberAccounts[${ma_index}].id" value="${ma.id?if_exists}"></td>
						    </tr>
						</#list>
					<#else>
						<tr>
						   <td>1</td>
						   <td><input class="form-control phone-input" type="text" name="memberAccounts[0].phone" /></td>
						   <td><input class="form-control" type="text" name="memberAccounts[0].name" /></td>
						   <td><input class="form-control" type="text" name="memberAccounts[0].address" /></td>
						   <td><input class="form-control" type="text" name="memberAccounts[0].carNumber" /></td>
						   <td><a href='javascript:;' class='btn btn-default deletethis'>删除</a></td>
					    </tr>
					</#if>
				</table>
			</div>
		</div>
		</form>
	</div>
	

</@override>
<@override name="footer">
<script type="text/javascript">
	<#if message??>
		$.scojs_message("${message}", $.scojs_message.TYPE_ERROR);
	</#if>
	var phone_num=$(".deletethis").length;
	$(document).ready(function(){
		
		$(document).on('click','.deletethis',function(){
			$(this).parent().parent().remove();
		});
		
		$("#add-phone").click(function(){
			$("#phone-table tbody").append("<tr>"+
										   "<td>"+(phone_num+1)+"</td>"+
										   "<td><input class='form-control phone-input' type='text' name='memberAccounts["+phone_num+"].phone'/></td>"+
										   "<td><input class='form-control' type='text' name='memberAccounts["+phone_num+"].name'/></td>"+
										   "<td><input class='form-control' type='text' name='memberAccounts["+phone_num+"].address'/></td>"+
										   "<td><input class='form-control' type='text' name='memberAccounts["+phone_num+"].carNumber'/></td>"+
										   "<td><a href='javascript:;' class='btn btn-default deletethis'>删除</a></td>"+
										   "</tr>");
			phone_num++;
		});
		
		$("#submit_form").submit(function(){
			var isphone=/^\+?\d{3,13}(\-?(\d{6,8}?))?(\-?(\d{4,8}?))*$/; 
			var isRightPhone=true; 
			
			if($(".phone-input").length==0){
				$.scojs_message("至少填写一条关联手机", $.scojs_message.TYPE_ERROR);
				return false;
			}
			
			$(".phone-input").each(function(index,element){
				var phone=$(element).val();
				if (!isphone.test(phone)){
					isRightPhone=false;
					return false;
				}
			});
			
			if(!isRightPhone){
				$.scojs_message("手机号格式不正确", $.scojs_message.TYPE_ERROR);
				return false;
			}
			
			$(this).attr("disabled",true);
			
			return true;
			
		});
		
		$("#type").change(function(){
			window.location="${ctx}/member/edit/${member.id}?typechange="+$(this).find("option:selected").attr("data-type");
		});
	});
</script>
</@override>
<@extends name="../layout.ftl"/>